// 实现首页轮播图效果
const carouselImg=document.getElementsByClassName('carouselImg');
const carousel=document.querySelector('.carousel')
const lastBtn=document.querySelector('.last');
const nextBtn=document.querySelector('.next');
const carouselIMgBox=document.querySelector('.carouselImgBox');
if(carouselImg && carousel && lastBtn && nextBtn) {
    let currentIndex=0;
    carouselImg[currentIndex].classList.add('showImg');

// 鼠标移入时显示按键
    if(carousel && lastBtn && nextBtn) {

        carousel.addEventListener('mouseenter',function (){
            lastBtn.style.display='inline';
            nextBtn.style.display='inline';
        })

        // 实现点击左右按键图片滑动效果
        lastBtn.addEventListener('click',function (){
            carouselImg[currentIndex].classList.remove('showImg');
            currentIndex = (currentIndex + 1) % carouselImg.length;
            carouselImg[currentIndex].classList.add('showImg');
        })
        nextBtn.addEventListener('click',function (){
            carouselImg[currentIndex].classList.remove('showImg');
            currentIndex = (currentIndex + 1) % carouselImg.length;
            carouselImg[currentIndex].classList.add('showImg');
        })

        // 鼠标移出时隐藏按键
        carousel.addEventListener('mouseleave',function (){
            lastBtn.style.display='none';
            nextBtn.style.display='none';
        })
        // 实现自动轮播功能
        function startAutoPlay() {
            setInterval(function (){
                carouselImg[currentIndex].classList.remove('showImg');
                currentIndex = (currentIndex + 1) % carouselImg.length;
                carouselImg[currentIndex].classList.add('showImg');
            },3000)
        }
        startAutoPlay();
    }
}



// 实现用户登录成功后鼠标悬停显示个人信息
const userTrigger=document.querySelector('.user-trigger');
const dropdownMenu=document.querySelector('.dropdown-menu');
const userDropdown=document.querySelector('.user-dropdown');
if(userTrigger && dropdownMenu && userDropdown) {
    if(userTrigger && dropdownMenu) {
        userTrigger.addEventListener('mouseenter', function(e) {
            e.stopPropagation(); // 阻止事件冒泡到文档
            dropdownMenu.classList.toggle('active');
        });
        // 点击其他区域关闭下拉菜单
        userDropdown.addEventListener('mouseleave', function() {
            dropdownMenu.classList.remove('active');
        });
    }
}

